package _interview150;

import _object.TreeNode;

/**
 * 98. 验证二叉搜索树
 */
public class No98 {
    private boolean ans = true;
    private long preVal = Long.MIN_VALUE;

    public boolean isValidBST(TreeNode root) {
        dfs(root);
        return ans;
    }

    private void dfs(TreeNode node) {
        if (node == null) return;
        dfs(node.left);
        if (node.val <= preVal) {
            ans = false;
            return;
        }
        preVal = node.val;
        dfs(node.right);
    }
}
